package com.chixing.service.impl;

import com.chixing.mapper.CartMapper;
import com.chixing.pojo.Cart;
import com.chixing.pojo.CartExample;
import com.chixing.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<Cart> getAll() {
        return cartMapper.selectByExample(null);
    }

    @Override
    public Cart getById(Integer cartId) {

        return cartMapper.selectByPrimaryKey(cartId);
    }

    @Override
    public List<Cart> getByCustomerId(Integer customerId) {

        CartExample cartExample = new CartExample();
        CartExample.Criteria criteria = cartExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);

        return cartMapper.selectByExample(cartExample);

    }
}
